﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ModelViewer
{
    public partial class OptionsDlg : Form
    {
        public Color BackgroundColor = Color.White;
        public Color AxisColorX = Color.Red;
        public Color AxisColorY = Color.Green;
        public Color AxisColorZ = Color.Blue;
        public Color AmbientColor = Color.Gray;

        public OptionsDlg()
        {
            InitializeComponent();
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void OptionsDlg_Load(object sender, EventArgs e)
        {
            UpdateUI();
        }

        private void UpdateUI()
        {
            buttonBackColor.BackColor = BackgroundColor;
            buttonAxisColorX.BackColor = AxisColorX;
            buttonAxisColorY.BackColor = AxisColorY;
            buttonAxisColorZ.BackColor = AxisColorZ;
            buttonAmbientColor.BackColor = AmbientColor;
        }

        private void buttonBackColor_Click(object sender, EventArgs e)
        {
            colorDialog.Color = BackgroundColor;
            if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                BackgroundColor = colorDialog.Color;
                UpdateUI();
            }
        }

        private void buttonAxisColorX_Click(object sender, EventArgs e)
        {
            colorDialog.Color = AxisColorX;
            if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                AxisColorX = colorDialog.Color;
                UpdateUI();
            }
        }

        private void buttonAxisColorY_Click(object sender, EventArgs e)
        {
            colorDialog.Color = AxisColorY;
            if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                AxisColorY = colorDialog.Color;
                UpdateUI();
            }
        }

        private void buttonAxisColorZ_Click(object sender, EventArgs e)
        {
            colorDialog.Color = AxisColorZ;
            if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                AxisColorZ = colorDialog.Color;
                UpdateUI();
            }
        }

        private void buttonAmbientColor_Click(object sender, EventArgs e)
        {
            colorDialog.Color = AmbientColor;
            if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                AmbientColor = colorDialog.Color;
                UpdateUI();
            }
        }

        private void buttonDefaults_Click(object sender, EventArgs e)
        {
            Settings settings = new Settings();
            settings.Reset();

            BackgroundColor = settings.BackgroundColor;
            AxisColorX = settings.AxisColorX;
            AxisColorY = settings.AxisColorY;
            AxisColorZ = settings.AxisColorZ;
            AmbientColor = settings.AmbientColor;

            UpdateUI();
        }
    }
}
